﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Specialized;
using Lifang.Entites;
using Lifang.Dao;

namespace Lifang.API.Controllers
{
    [Produces("application/json")]
    [Route("api/ArticleContent")]
    public class ArticleContentController : BaseController
    {

        [HttpGet("ValidList")]
        public JsonResult ValidList()
        {
            var dp = Pager;
            dp.OrderField = " Id  ASC  ";
            var nvc = new NameValueCollection();
            if(Request.Query!=null)
            {
                foreach(var key in Request.Query.Keys)
                {                    
                    nvc.Add(key, Request.Query[key]);
                }
            }
            var list = new CommonQuery().SelectViewPagerByKey<DP_ArticleContent>("ArticleContentView", nvc, dp);
            Pager = dp;
            return Json(list);
        }

        [HttpGet("Detail")]
        public JsonResult GetById(int id)
        {
            var mod = new DapperHelper().SelectModel<DP_ArticleContent>(id, new SqlNote("cxg", "查询栏目列表"));
            return Json(mod);
        }

        [HttpGet("Save")]
        public JsonResult SaveOrUpdate(DP_ArticleContent mod)
        {
            mod = new DP_ArticleContent();
            mod.ArticleId = 1;
            mod.Content = "测试content测试哈哈哈";
            mod.CreateDateTime = DateTime.Now;
            mod.CreateUserName = "蔡小光";
            mod.CreateUserNo = "02773";
            mod.DataFlag = 1;
            mod.ImageType = 1;
            mod.ImageUrlOne = "http://www.ly.com/1.png";
            mod.ImageUrlTwo = "http://www.ly.com/2.png";
            mod.IsDel = 0;
            mod.UpdateDateTime = DateTime.Now;
            mod.UpdateUserName = "蔡小光";
            mod.UpdateUserNo = "02773";            
            new ArticleContentDao(LoginUserModel).SaveOrUpdateMod(mod, new SqlNote("cxg", "更新数据"));
            return Json(mod);
        }
    }
}